import com.sun.jdi.Value;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LIUYANJIAO
 * Date: 2024-05-30
 * Time: 18:15
 */
public class Main {
    public static boolean isValid(String s) {
        char[]arr=s.toCharArray();
        int[] arr1=new int[6];
        int b=0;
        for (int i = 0; i < arr.length; i++) {
            switch(arr[i]){
                case '(':
                    b++;
                    arr1[0]++;
                    break;
                case ')':
                    if(b==0) return false;
                    b--;
                    arr1[1]++;
                    break;
                case '[':
                    b++;
                    arr1[2]++;
                    break;
                case ']':
                    if(b==0) return false;
                    b--;
                    arr1[3]++;
                    break;
                case '{':
                    b++;
                    arr1[4]++;
                    break;
                case '}':
                    if(b==0) return false;
                    b--;
                    arr1[5]++;
                    break;
            }
        }
        if(arr1[0]==arr1[1]&&arr1[2]==arr1[3]&&arr1[4]==arr1[5]) return true;
        else return false;

    }

    public static void main(String[] args) {
        System.out.println(isValid("{[]}"));
    }
    public static String longestCommonPrefix(String[] strs) {
     //找最长前缀
        Arrays.sort(strs);
        char[]a=strs[0].toCharArray();
        char[]b=strs[strs.length-1].toCharArray();
        char[]arr=new char[a.length];
        int n=0;
        for (int i = 0; i < a.length; i++) {
            if(a[i]==b[i]){
                arr[n++]=a[i];
            }else{
                return String.valueOf(arr).substring(0,n);
            }
        }return String.valueOf(arr).substring(0,n);//String.valueOf()将数组转化为字符串
                                                   //substring（）打印范围内的字符串


    }
    public static boolean isPalindrome(int x) {
        String a=Integer.toString(x);//将int类型转换成字符串类型
        String b= new StringBuilder(a).reverse().toString();//反置字符串
        return a.equals(b);//字符串比较


    }
//    public boolean isPalindrome(int x) {
//        String s=Integer.toString(x);
//        char arr[]=s.toCharArray();
//        //char[] arr1=StringBuilder(arr).toCharArray;
//
//    }
    public static void main1(String[] args) {
        //Palindrome Number
        //System.out.println(isPalindrome(-121));
        //System.out.println(romanToInt("MCMXCIV"));
        String[]arr={"dog","racecar","car"};
        //System.out.println(longestCommonPrefix(arr));

    }
}